from pages.login import LoginPage
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
class Scheduler(LoginPage):
    def __init__(self, driver):
        self.driver = driver
    def addIntervalAndAction(self):
        self.driver.find_element(By.CSS_SELECTOR, ".nav-link:nth-child(5) > span").click()
        self.driver.find_element(By.CSS_SELECTOR, ".btn-info > span > span").click()
        self.driver.find_element(By.ID, "validationIntervalName").click()
        self.driver.find_element(By.ID, "validationIntervalName").send_keys("test-interval-01")
        # time.sleep(1)
        # self.driver.find_element(By.NAME, "intervalStart").click()
        # self.driver.find_element(By.CSS_SELECTOR, ".open .today").click()
        # self.driver.find_element(By.NAME, "intervalStart").send_keys("20211220T120000")
        # time.sleep(1)
        # self.driver.find_element(By.CSS_SELECTOR, ".card-body > .ng-invalid").click()
        # self.driver.find_element(By.NAME, "intervalEnd").click()
        # self.driver.find_element(By.CSS_SELECTOR, ".open .today").click()
        # self.driver.find_element(By.NAME, "intervalEnd").send_keys("20211220T120000")
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, ".form-group:nth-child(3) > .col-md-2").click()
        self.driver.find_element(By.NAME, "intervalInterval").click()
        self.driver.find_element(By.NAME, "intervalInterval").send_keys("24h")
        time.sleep(1)
        self.driver.find_element(By.NAME, "intervalRunOnce").click()
        dropdown = self.driver.find_element(By.NAME, "intervalRunOnce")
        dropdown.find_element(By.XPATH, "//option[. = 'false']").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, ".custom-select > option:nth-child(1)").click()
        self.driver.find_element(By.CSS_SELECTOR, ".card-body > .ng-dirty").click()
        self.driver.find_element(By.CSS_SELECTOR, ".btn-success").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".btn-success")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, ".nav-item:nth-child(2) span").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, ".btn-info > span > span").click()
        # time.sleep(1)
        # element = self.driver.find_element(By.CSS_SELECTOR, ".btn-info > span > span")
        # actions = ActionChains(self.driver)
        # actions.move_to_element(element).perform()
        time.sleep(1)
        self.driver.find_element(By.ID, "validationIntervalActionName").click()
        self.driver.find_element(By.ID, "validationIntervalActionName").send_keys("test-interval-action-01")
        time.sleep(1)
        self.driver.find_element(By.NAME, "selectedInterval").click()
        self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(1) input").click()
        self.driver.find_element(By.CSS_SELECTOR, ".combo-shielder").click()
        time.sleep(1)
        self.driver.find_element(By.ID, "EMAIL").click()
        self.driver.find_element(By.ID, "emailRecipients").click()
        self.driver.find_element(By.ID, "emailRecipients").send_keys("huaqiaoz@vmware.com")
        self.driver.find_element(By.CSS_SELECTOR, ".ng-dirty > .form-group:nth-child(2) > .col-md-2").click()
        self.driver.find_element(By.CSS_SELECTOR, ".btn-success").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".btn-success")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
